<template>
  <div class="order_container">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row :gutter="20">
        <el-col :span="9">
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            class="input-with-select"
            clearable
            @clear="getOrderList"
          >
            <el-button slot="append" icon="el-icon-search" @click="serach"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList">
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template slot-scope="scope">
            <el-tag type="warning" v-if="scope.row.pay_status === '0'">未付款</el-tag>
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">{{ scope.row.create_time | dateFilter}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-tooltip effect="dark" content="修改地址" placement="top" :enterable="false">
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                @click="changeAddressVisi= true"
              ></el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="查看物流信息" placement="top" :enterable="false">
              <el-button
                type="success"
                icon="el-icon-location-outline"
                size="mini"
                @click="getKuaidi"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog title="修改地址" :visible.sync="changeAddressVisi">
      <el-form ref="changeAddress" label-width="120px" :rules="addressRules">
        <el-form-item label="省市区/县" prop="add1">
          <el-cascader :options="cityOptions" :value="city" change-on-select></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="add2">
          <el-input autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="changeAddressVisi = false">取 消</el-button>
        <el-button type="primary" @click="changeAddressVisi = false">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 查看物流信息对话框 -->
    <el-dialog title="物流信息" :visible.sync="kuaidiVisi">
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(activity, index) in kuaidi"
          :key="index"
          :timestamp="activity.ftime"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityOptions from '../../assets/js/city_data2017_element'
export default {
  data () {
    return {
      // 订单查询对象
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 30
      },
      orderList: [],
      total: '',
      // 修改地址对话框的显示隐藏
      changeAddressVisi: false,
      // 省市区数据
      cityOptions: cityOptions,
      addressRules: {
        add1: [
          { required: true, message: '请输入省市区一级地址', trigger: 'blur' }
        ],
        add2: [{ required: true, message: '请输入详细地址', trigger: 'blur' }]
      },
      kuaidiVisi: false,
      // 查询的物流信息
      kuaidi: []
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单信息失败')
      }
      this.total = res.total
      this.orderList = res.data.goods
      console.log(res)
    },
    serach () {
      this.queryInfo.pagenum = 1
      this.getOrderList()
    },
    async getKuaidi () {
      const { data: res } = await this.$http.get('/kuaidi/804909574412544580')

      if (res.meta.status !== 200) {
        return this.$message.error('获取物流进度失败！')
      }

      this.kuaidi = res.data

      this.kuaidiVisi = true
      console.log(this.kuaidi)
    }
  }
}
</script>

<style lang='less' scoped>
.el-cascader {
  width: 100%;
}
</style>
